package Model.Beans;

import java.beans.*;
import java.io.Serializable;
import Model.XML.*;

public class Course extends Object implements Serializable, XMLRequestInterface
{
    private int id = 0;
    private ClassRoom classRoom = new ClassRoom();
    private String days = "";
    private String codeCourse = "";
    private Person professor = new Person();
    private String time = "";
    private String title = "";
    private XMLWriter xml;

    public Course() 
    {
        xml = new XMLWriter();
    }
    
    public Course(int id, ClassRoom classRoom, String days, String codeCourse, Person professor, String time, String title)
    {
        this.id = id;
        this.classRoom = classRoom;
        this.days = days;
        this.codeCourse = codeCourse;
        this.professor = professor;
        this.time = time;
        this.title = title;
        xml = new XMLWriter();
    }
    
    public Course(ClassRoom classRoom, String days, String codeCourse, Person professor, String time, String title)
    {
        this(0, classRoom, days, codeCourse, professor, time, title);
    }
    
    public int getId()
    {
        return id;
    }
    
    public void setId(int id)
    {
        this.id = id;
    }
    
    public ClassRoom getClassRoom()
    {
        return classRoom;
    }
    
    public void setClassRoom(ClassRoom classRoom)
    {
        this.classRoom = classRoom;
    }
    
    public String getDays()
    {
        return days;
    }
    
    public void setDays(String days)
    {
        this.days = days;
    }
    
    public String getCodeCourse()
    {
        return codeCourse;
    }
    
    public void setCodeCourse(String codeCourse)
    {
        this.codeCourse = codeCourse;
    }
    
    public Person getProfessor()
    {
        return professor;
    }
    
    public void setProfessor(Person professor)
    {
        this.professor = professor;
    }
    
    public String getTime()
    {
        return time;
    }
    
    public void setTime(String time)
    {
        this.time = time;
    }
    
    public String getTitle()
    {
        return title;
    }
    
    public void setTitle(String title)
    {
        this.title = title;
    }
    
    public String toString()
    {
        StringBuilder result = new StringBuilder();
        result.append(this.title + " - " + this.codeCourse);
        return result.toString();
    }
    
    
    public String toXML()
    {
        xml.Push("course");
        xml.Element("id", Integer.toString(this.id));
        xml.Element("title", this.title);
        xml.Element("code-course", this.codeCourse);
        xml.Element("professor", this.professor.toString(), Integer.toString(professor.getId()));
        xml.Element("classroom", this.classRoom.toString(), Integer.toString(classRoom.getId()));
        xml.Element("days", this.days);
        xml.Element("hour", this.time);
        xml.Pop();
        return xml.GetXML();
    }
}
